package com.collection.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class WebsiteStrategy implements Serializable {
	
	private static final long serialVersionUID = -4384814202307149251L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	private boolean autoPage;
	
	private String url;
	
	private String charCode;
	
	@OneToMany(targetEntity = UrlParam.class,cascade = CascadeType.ALL)
    @JoinColumn(name="websiteStrategy_id",referencedColumnName="id")
	private List<UrlParam> urlParams;
	
	@OneToMany(targetEntity = BaseStrategy.class,cascade = CascadeType.ALL)
    @JoinColumn(name="websiteStrategy_id",referencedColumnName="id")
	private List<BaseStrategy> baseStrategies;
	
	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="collectionTask_id")
	private CollectionTask collectionTask;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public List<UrlParam> getUrlParams() {
		return urlParams;
	}

	public void setUrlParams(List<UrlParam> urlParams) {
		this.urlParams = urlParams;
	}

	public boolean isAutoPage() {
		return autoPage;
	}

	public void setAutoPage(boolean autoPage) {
		this.autoPage = autoPage;
	}

	public String getCharCode() {
		return charCode;
	}

	public void setCharCode(String charCode) {
		this.charCode = charCode;
	}

	public List<BaseStrategy> getBaseStrategies() {
		return baseStrategies;
	}

	public void setBaseStrategies(List<BaseStrategy> baseStrategies) {
		this.baseStrategies = baseStrategies;
	}

	public CollectionTask getCollectionTask() {
		return collectionTask;
	}

	public void setCollectionTask(CollectionTask collectionTask) {
		this.collectionTask = collectionTask;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj != null && (obj instanceof WebsiteStrategy)) {
			return ((WebsiteStrategy) obj).getId().equals(id);
		}
		return super.equals(obj);
	}

	@Override
	public int hashCode() {
		if (getId() == null) {
			return super.hashCode();
		} else {
			return this.getId().hashCode();
		}
	}
}
